package com.taiji.web.controller.workOrder;

import com.taiji.common.core.controller.BaseController;
import com.taiji.common.core.domain.AjaxResult;
import com.taiji.common.utils.SecurityUtils;
import com.taiji.workOrder.service.IMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author -1
 * @since 2023/07/06 9:54
 * description:
 */
@RestController
@RequestMapping("/message")
@Api(tags = "工单消息")
public class MessageController extends BaseController {

    @Autowired
    private IMessageService messageService;

    /**
     * 获取消息通知
     * @return
     */
    @GetMapping
    @ApiOperation("获取当前用户消息通知")
    public AjaxResult getMyMessageInfo(){
        String username = SecurityUtils.getUsername();
        return AjaxResult.success(messageService.findMessageInfoByUserName(username));
    }

    /**
     * 修改消息状态为已读
     * @param id 消息id
     */
    @PutMapping("/{id}")
    @ApiOperation("修改消息状态为已读")
    public AjaxResult readMessage(@PathVariable String id){

        return toAjax(messageService.updateMessageStatusById(id));
    }
}
